package com.zky.gulimall.product;

import java.util.concurrent.TimeUnit;

/**
 * @Description TODO
 * @Author 张开源
 * @Date 2022/11/12 11:16
 * @Version 1.0
 **/
public class JmmDemo {
    static volatile boolean flag = true;

    public static void main(String[] args) {

        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "\t---------------come in");
            while (flag) {

            }
            System.out.println(Thread.currentThread().getName() + "\t---------------flag 被设置为false，程序停止");
        }, "t1").start();

        try {
            TimeUnit.MILLISECONDS.sleep(20);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


        new Thread(() -> {
            flag = false;
            System.out.println(Thread.currentThread().getName() + "\t---------------修改完成flag:" + flag);
        }, "t2").start();

    }


}
